home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / A⁄ROSE / OSmainƒ / myTask.c next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  2.7 KB  |  109 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    myTask.c
  4. #
  5. #    To be compiled and linked together with "osmain.c.o",
  6. #    and downloaded to a MCP card.
  7. #
  8. #    The "ClientAppli" application will find "myTask" on a MCP card, 
  9. #   and have the messages sent to it echoed.
  10. #
  11. #    Components:
  12. #                osmain.c
  13. #                myTask.c
  14. #
  15. ------------------------------------------------------------------------------*/
  16.  
  17. #define    DUMMYCODE    900
  18.  
  19.  
  20. // definitions from "os.h":
  21.  
  22. typedef long    tid_type;
  23.  
  24. struct mMessage
  25. {
  26.     struct    mMessage    *mNext;
  27.     long                mId;
  28.     short                mCode;
  29.     short                mStatus;
  30.     unsigned    short    mPriority;
  31.     tid_type            mFrom;
  32.     tid_type            mTo;
  33.     unsigned    long    mSData [3];
  34.     unsigned    long    mOData [3];
  35.     long                mDataSize;    // Size of data buffer in bytes. set to negative
  36.                                         // size of buffer if buffer is shared
  37.                                         // between tasks. eg. Buffer cannot be copied
  38.     char                *mDataPtr;
  39. };
  40.  
  41. typedef struct mMessage mMessage;
  42.  
  43. #define    OS_MATCH_ALL    0        // on receive match anything
  44. #define    OS_NO_TIMEOUT    0        // receive waits forever for message
  45.  
  46. // some #define's from "managers.h":
  47.  
  48. #define    OS_UNKNOWN_MESSAGE        (1<<8)    // unrecognized message code
  49. #define    Machine_Visible            0            // Register_task Machine visible flag
  50.  
  51.  
  52. void myTask();
  53. extern char        Register_Task(char *, char *, short);
  54. extern mMessage *Receive(unsigned long, tid_type, unsigned short, long, ...);
  55. extern void        FreeMsg();
  56. extern void        SwapTID(mMessage *);
  57. extern void        Send(mMessage *);
  58.  
  59. pascal void illegal ()    extern    0x4afc;
  60.         
  61. static    char    my_object_name [] = "myTaskName";
  62. static    char    my_type_name []   = "myTaskType";
  63.  
  64. void myTask()
  65. // all it does at this point is to register with the Name Manager
  66. // (in order to be recognized by possible clients looking for it)
  67. // and then just send back the messages it receives
  68.  
  69. {
  70.     mMessage *m;
  71.     
  72.     if (!Register_Task (my_object_name, my_type_name, Machine_Visible))
  73.         illegal ();    // go debugging: something mysterious happens
  74.                     
  75.     while(1)     // forever !
  76.     {
  77.     m = Receive(OS_MATCH_ALL, OS_MATCH_ALL, OS_MATCH_ALL, OS_NO_TIMEOUT);
  78.     if (m) {
  79.         if (m->mStatus != 0) { // what happens? Should investigate!
  80.             FreeMsg(m);      // I don't know: better get rid of it
  81.         }
  82.         else {
  83.             switch (m->mCode)    {
  84.             case DUMMYCODE:
  85.                 // is there something to do with this message ?
  86.                 break;
  87.         
  88.     // handle here all the message codes you specified in your design !
  89.             
  90.             default:
  91.                 m->mCode |= 0x8000;    // unrecognized message code;
  92.                 m->mStatus = OS_UNKNOWN_MESSAGE;
  93.                                 // defined in "managers.h"
  94.                 break;
  95.                 } // switch
  96.  
  97.                 // send message back
  98.                 SwapTID(m);        // swap mFrom <-> mTo fields
  99.                 m->mCode++;        // by convention
  100.                 Send(m);
  101.     
  102.             }    // message status was OK
  103.  
  104.         }    // there was a message
  105.     
  106.     }  // while (1)
  107.  
  108. }    // end myTask()
  109.